package com.abel.demo.services.impl;

import com.abel.demo.dao.UserInfoModelDao;
import com.abel.demo.dao.BaseDao;
import com.abel.demo.dao.mapper.AuthorizeMapper;
import com.abel.demo.domain.UserInfoDomain;
import com.abel.demo.model.SecAuthorityModel;
import com.abel.demo.model.SecRoleModel;
import com.abel.demo.model.UserInfoModel;
import com.abel.demo.model.UserInfoModelCriteria;
import com.abel.demo.services.UserInfoService;
import com.abel.demo.utils.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author abel.lin
* @date_time 2018-07-11 18:26
* @description
*/
@Service
public class UserInfoServiceImpl
    extends BaseServiceImpl<BaseDao<UserInfoModel,UserInfoModelCriteria>,UserInfoModel,UserInfoModelCriteria>
    implements UserInfoService {

    @Autowired
    private UserInfoModelDao userInfoModelDao;
    @Autowired
    private AuthorizeMapper authorizeMapper;

    public UserInfoServiceImpl(){
        super.baseMapper = userInfoModelDao;
    }

    @Override
    public UserInfoDomain getUserDomainByUserName(String userName) {
        UserInfoModelCriteria query = new UserInfoModelCriteria();
        query.createCriteria().andUserNameEqualTo(userName);
        List<UserInfoModel> list = userInfoModelDao.selectByExample(query);
        if(!BaseUtil.isEmpty(list)){
            UserInfoDomain domain = UserInfoDomain.genDomain(list.get(0));
            return domain;
        }
        return null;
    }

    @Override
    public List<SecAuthorityModel> selectAuthoritiesByUserName(String userName) {
        return authorizeMapper.selectAuthoritiesByUsername(userName);
    }

    @Override
    public List<SecRoleModel> selectRolesByUserName(String userName) {
        return authorizeMapper.selectRolesByUsername(userName);
    }
}
